package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/*
*
* 日报
* */
@Setter @Getter @AllArgsConstructor @NoArgsConstructor
public class Daily extends BaseDomain{

    public static final Integer STATE_DISABLE= -1;//草稿
    public static final Integer STATE_NORMAL= 0;//草稿
    public static final Integer STATE_RELEASE = 1;//发布

    //日报标题
    private String title;

    private Integer num = 0;

    //日报封面
    private String coverUrl;

    //日报创建时间
    @JsonFormat(pattern = "yyy-MM-dd",timezone = "GMT+8")
    private Date creatTime;

    //日报副标题
    private String subtitle;

    //日报状态
    private Integer state=STATE_NORMAL;


    //日报内容对象
    private DailyContent dailyContent;

    private NewsCatalog newsCatalog;


    //提供json 属性因用于模态框数据回显
    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("subtitle",subtitle);
        map.put("coverUrl",coverUrl);
        map.put("creatTime",creatTime);
        map.put("state",state);
        if(dailyContent != null){
            map.put("content",dailyContent.getContent());
        }

        return JSONUtils.toJSONString(map);
    }

    public String getStateName(){
        String temp = "正常";
        if(state == STATE_DISABLE){
            temp = "禁用";
        }else if(state == STATE_RELEASE){
            temp = "发布";
        }
        return temp;
    }

}